//大于固定字符串显示省略号
export function handleStr(str, length) {
  let handle_str;
  str.length <= length ? handle_str = str : handle_str = str.slice(0, length) + "...";
  return handle_str
}


//隐藏部分字符串
export function hideStr(str, frontLen, endLen, zhanweifu = '*') {
  var len = str.length - frontLen - endLen;
  var xing = '';
  for (var i = 0; i < len; i++) {
    xing += zhanweifu;
  }
  return str.substring(0, frontLen) + xing + str.substring(str.length - endLen);
}
export function toast(title) {
  uni.showToast({
    icon: 'none',
    title: title
  })
}

/**
 * 显示Loading
 */
export function show( msg = "加载中") {
	uni.showLoading({
		title: msg,
		mask: true,
		duration: 20000

	});
}

/**
 * 关闭Loading
 */
export function hide(msg) {
	uni.hideLoading();
	if(msg){
		uni.showToast({
		  icon: 'none',
		  title: msg
		})
	}
}

/**
 * 关闭Loading
 */
export function error(e) {
	uni.hideLoading();

	uni.showToast({
	  icon: 'none',
	  title: e.message?e.message:e
	})
}
export function showConfirm(content,cancelText="取消",confirmText="确定") {
  return new Promise((resolve, reject) => {
    uni.showModal({
      title: '提示',
      content: content,
      cancelText:cancelText ,
      confirmText: confirmText,
      success: function(res) {
        resolve(res);
      }
    });
  });
}
export function showActionSheet(content = ['确定', '取消']) {
  return new Promise((resolve, reject) => {
    uni.showActionSheet({
      itemList: content,
      success: function(res) {
        resolve(res)
      },
    });
  })
}

